/*
 * @Author: your name
 * @Date: 2021-08-13 14:39:38
 * @Description: 工具函数
 * @FilePath: /wx-weapp/utils/enhancer/utils/util.js
 */

const _toString = Object.prototype.toString;
//判断变量类型
export function isType(_var) {
  return Object.prototype.toString.call(_var).slice(8, -1).toLowerCase();
}

export function isPlainObject(obj) {
  return _toString.call(obj) === "[object Object]";
}

export function isObject(obj) {
  return obj !== null && typeof obj === "object";
}
export function isUndef(v) {
  return v === undefined || v === null;
}

export const hasProto = "__proto__" in {};

export function hasOwn(obj, key) {
  return Object.prototype.hasOwnProperty.call(obj, key);
}

export function noop() {}

export function deepClone(obj){
  if(obj!=null && !isObject(obj)){
    return obj
  }
  let result = {}
  if(Array.isArray(obj)){
    result = []
  } 
  for(let k in obj){
    result[k] = deepClone(obj[k])
  }
  
  return result
}

export function parsePath(path) {
  let segments = path.split('.');
  return function (obj) {
      obj = obj.data;
      for (let seg of segments) {
        if (!obj) return;
        obj = obj[seg];
      }
      return deepClone(obj);
  };
}